<template>
	<view>
		<view class="container">
			<view class="list" v-for="(good,index) in dataList" @click="turntoUpdate(good.id)">
				<view class="image">
					<image :src="good.imageUrl" mode="scaleToFill" :lazy-load='true'></image>
				</view>
				<view class="name">
					<text>{{good.name}}</text>
				</view>
				<!-- <view class="info">
					<text>{{good.barcode}}</text>
				</view> -->
				<view class="price">
					<!-- <view class="left">
						<text>库存:{{}}</text>
					</view> -->
					<view class="right">
						<text>￥{{good.salePrice}}</text>
					</view>
				</view>
			</view>
			<uni-fab ref="fab" :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction"
				@trigger="trigger" @fabClick="fabClick" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'uni-fab',
				directionStr: '垂直',
				horizontal: 'right',
				vertical: 'top',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#007AFF',
					iconColor: '#fff'
				},
				is_color_type: false,
				dataList: [],
				pageSize: 6,
				total: '',
				pageNo: 1,
			}
		},
		onShow() {
			this.pageNo=1;
			this.pageSize=6;
			this.getGoodsList()

		},
		// 触底的事件
		onReachBottom() {
			console.log('触底了');
			// 判断是否还有下一页数据
			if (this.pageNo * this.pageSize >= this.total) return uni.$showMsg('数据加载完毕！')
			// 让页码值自增 +1
			this.pageNo += 1
			// 重新获取列表数据
			this.getGoodsList(true)
		},
		methods: {
			turntoUpdate(id) {
				uni.navigateTo({
					url: `/subpkg/UpdateGoods/UpdateGoods?id=${id}`
				})
			},
			async getGoodsList(onReachBottom) {
				const data = {
					goodsType: 0,
					storeId: uni.getStorageSync('storeId'),
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				};
				const {
					data: res
				} = await uni.$http.post(
					`/store/storeGoodsQuery`, data
				);
				if (res.code !== 0) return uni.$showMsg(res.message);
				// 为数据赋值：通过展开运算符的形式，进行新旧数据的拼接
				if (onReachBottom) {
					this.dataList = [...this.dataList, ...res.data.data.records]
					return
				}
				this.dataList = res.data.data.records;
				this.total = res.data.data.total;
				console.log(res.data, '门店全部商品!');

			},
			fabClick() {
				uni.navigateTo({
					url: "/subpkg/NewGoods/NewGoods"
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		// height: 80vh;
		// overflow-y: auto;
		display: flex;
		flex-wrap: wrap;
		padding-bottom: 8vh;
	}

	.list {
		width: 40vw;
		height: 35vh;
		padding: 3vw;
		margin: 2vw;
		background-color: #fff;

		.image {
			width: 40vw;
			height: 40vw;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.name {
			font-size: 30rpx;
			font-weight: 700;
			margin-top: 2vh;
		}

		.info {
			font-size: 26rpx;
			color: #bcbab8;
			margin-top: 2vh;
		}

		.price {
			margin-top: 2vh;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				color: #5199e8;
				font-size: 4vw;
			}

			.right {
				color: #ff8091;
				font-size: 5vw;
			}
		}
	}
</style>